package com.bigflexlib.utils
{
	[Bindable]
	/**
	 * 
	 * A standard, minimalistic info tuple used throughout the system.
	 * 
	 * @author aldo.bucchi@univrz.com
	 * @see https://trac.univrz.com/main/wiki/RDFValueSerialization
	 */
	public class Info
	{
		public var label:String;
		public var description:String;
		public var image:String;
		
		public function Info()
		{
		}
		
		/**
		 * 
		 * 
		 * 
		 * <pre>
		 * node =
		 * <SomeNode>
		 *   <info>
		 *    <Info label="Foo Bar" image="http://.../foo.png">
		 *      This is a description
		 *    </Info>
		 *  </info>
		 * </SomeNode> 
		 * </pre>
		 * 
		 * @param node
		 * @return 
		 * 
		 */
		public static function forNode( node:XML ):Info
		{
			try{
				return forInfoNode(node.info.Info[0]);
			}catch(e:Error){}
			return new Info(); // do we return a null info?
		}
		
		/**
		 * <pre>
		 * infoNode=
		 *    <Info label="Foo Bar" image="http://.../foo.png">
		 *      This is a description
		 *    </Info>
		 * </pre>
		 * 
		 * @param infoNode
		 * @return 
		 * 
		 */
		public static function forInfoNode( infoNode:XML ):Info
		{
			var info:Info = new Info();
			try{ info.label = infoNode.@label.toString();
			}catch(e:Error){}
			
			try{ info.description = infoNode.text().toString();
			}catch(e:Error){}
			
			try{ info.image = infoNode.@image.toString();
			}catch(e:Error){}

			return info;
		}
	}
}